package com.ws.user.user.service.impl;

import com.ws.common.easyui.util.Page;
import com.github.pagehelper.PageHelper;
import com.ws.user.user.dao.UserRoleMapper;
import com.ws.user.user.entity.UserRole;
import com.ws.user.user.service.IUserRoleService;
import com.ws.common.base.service.Impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class UserRoleServiceImpl extends BaseServiceImpl<UserRole> implements IUserRoleService{

	@Autowired
	UserRoleMapper userRoleMapper;

	@Override
	public List<UserRole> list(UserRole params) {
		return userRoleMapper.list(params);
	}

	@Override
	public List<UserRole> list(UserRole params, Page page) {
		PageHelper.startPage(page.getPage(),page.getRows(),page.getSortOrder());
		return userRoleMapper.list(params);
	}

	@Override
	public Integer save(UserRole userRole) {
		return this.insertOrUpdate(userRole);
	}

	@Override
	public Integer deleteByUserId(String userId) {

		return userRoleMapper.deleteByUserId(userId);
	}

	@Override
	public List<String> listRoleByUserId(String userId) {
		UserRole userRole=new UserRole();
		userRole.setUserId(userId);
		List<UserRole> userRoles=userRoleMapper.list(userRole);
		List<String> roleIds=new ArrayList<>();
		for(UserRole u : userRoles){
			roleIds.add(u.getRoleId());
		}
		return roleIds;
	}
}
